package org.jeecg.modules.reserve.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.zxing.WriterException;
import org.jeecg.modules.reserve.entity.SdxcReservePlace;
import org.jeecg.modules.reserve.mapper.SdxcReservePlaceMapper;
import org.jeecg.modules.reserve.service.ISdxcReservePlaceService;
import org.jeecg.modules.reserve.utils.QRCodeGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.io.IOException;
import java.util.List;

/**
 * @Description: 场地配置
 * @Author: jeecg-boot
 * @Date:   2020-09-14
 * @Version: V1.0
 */
@Service
public class SdxcReservePlaceServiceImpl extends ServiceImpl<SdxcReservePlaceMapper, SdxcReservePlace> implements ISdxcReservePlaceService {
    @Autowired
    private SdxcReservePlaceMapper sdxcReservePlaceMapper;

    /**
     * 上传路径
     */
    @Value ("${jeecg.path.upload}")
    private String uploadPath;

    @Override
    public boolean add(SdxcReservePlace sdxcReservePlace) throws IOException, WriterException {
        sdxcReservePlaceMapper.insert(sdxcReservePlace);
        //生成包含id信息的二维码
        String qrCode = "/" + sdxcReservePlace.getId() + ".png";
        QRCodeGenerator.generateQRCodeImage(sdxcReservePlace.getId(), 350, 350, uploadPath + qrCode);
        sdxcReservePlace.setQrCode(qrCode);
        sdxcReservePlaceMapper.updateById(sdxcReservePlace);
        return true;
    }
    /**
     * 查询场地列表
     *
     * @param queryWrapper
     * @return
     */
    @Override
    public List<SdxcReservePlace> selectList(QueryWrapper queryWrapper) {
        return sdxcReservePlaceMapper.selectList(queryWrapper);
    }
}
